package com.sc.pattern.activeobjects;

/**
 * Created  on 2018/1/14.
 *
 * @author sc
 */
public class ScheduleThread extends Thread {
    private final ActivationQueue queue;

    public ScheduleThread(ActivationQueue queue) {
        this.queue = queue;
    }

    public void invoke(MethodRequest request){
        this.queue.put(request);
    }

    @Override
    public void run() {
        while (true){
            queue.take().execute();
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
